PACKAGE=command-not-found-data
VERSION := $(shell rpm -q --qf '%{version}\n' --specfile $(PACKAGE).spec | head -1)
RELEASE := $(shell rpm -q --qf '%{release}\n' --specfile $(PACKAGE).spec | head -1)
ARCH := $(shell rpm -q --qf '%{arch}\n' --specfile $(PACKAGE).spec | head -1)
ARCHIVEVER := $(VERSION)

TEXTDOMAIN   = ${PACKAGE}

RPM          = /usr/bin/rpm

PRODUCT      = "PCLinuxOS 2007"
export PRODUCT

MSGFMT       = /usr/bin/msgfmt

DESTDIR      =

bindir=/usr/bin
sbindir=/usr/sbin
datadir=/usr/share
cachedir=/var/cache
localedir=$(datadir)/locale
libdir=/usr/lib
etcdir=/etc


.PHONY: all clean installdirs install cleandist distdir localcopy tar rpm rpm-install

all: $(cachedir)/cnf/cnfcache.sqlite

$(cachedir)/cnf/cnfcache.sqlite:
	apt-get update
	cnf-update

installdirs:
	install -d -m 0755 $(DESTDIR)/$(cachedir)/cnf
	install -d -m 0755 $(DESTDIR)/$(libdir)/cnfbin


install: $(cachedir)/cnf/cnfcache.sqlite installdirs
	install -m 0644 $(cachedir)/cnf/cnfcache.sqlite $(DESTDIR)/$(cachedir)/cnf/
	echo tar czf $(DESTDIR)/$(libdir)/cnfbin/cnf_commands.tar.gz --exclude cnf_commands.tar.gz -C $(libdir)/cnfbin/ .
	tar czf $(DESTDIR)/$(libdir)/cnfbin/cnf_commands.tar.gz --exclude cnf_commands.tar.gz -C $(libdir)/cnfbin/ .

clean:
	rm -f $(PACKAGE)-$(ARCHIVEVER).tar.bz2

cleandist: clean
	rm -Rf $(PACKAGE)-$(VERSION)

distclean: clean
	rm -f $(cachedir)/cnf/cnfcache.sqlite

distdir:
	if [ ! -d $(PACKAGE)-$(VERSION) ]; then mkdir $(PACKAGE)-$(VERSION); fi

localcopy: clean distdir
	tar cp --exclude=.svn --exclude=$(PACKAGE)-$(VERSION) --exclude=*.tar.bz2 --exclude=*.tar.gz . | tar xp -C $(PACKAGE)-$(VERSION)
	
tar: cleandist localcopy
	tar cjvf $(PACKAGE)-$(ARCHIVEVER).tar.bz2 $(PACKAGE)-$(VERSION)
	rm -rf $(PACKAGE)-$(VERSION)

rpm: tar
	rpmbuild -ta $(PACKAGE)-$(ARCHIVEVER).tar.bz2

rpm-install: rpm
	rpm -Uvh --force /usr/src/rpm/RPMS/$(ARCH)/$(PACKAGE)-$(VERSION)-$(RELEASE).$(ARCH).rpm
